Here are plots of the current data for the number of deaths, hospitalizations, positive and negative tests for each state over time.
The cumulative plots show the total number in each category, while the log plots show the rate of change in each category. The raw change plots show the daily increase or decrease.
plot_covid = function(data, y, state = TRUE) {
if (isFALSE(state)) {
data = data %>%
group_by(date) %>%
summarize(deaths = sum(deaths, na.rm = TRUE),
deaths_change = sum(deaths_change, na.rm = TRUE),
hospitalizations = sum(hospitalizations, na.rm = TRUE),
hospitalizations_change = sum(hospitalizations_change, na.rm = TRUE),
positive_test_results = sum(positive_test_results, na.rm = TRUE),
positive_test_results_change = sum(positive_test_results_change, na.rm = TRUE),
negative_test_results = sum(negative_test_results, na.rm = TRUE),
negative_test_results_change = sum(negative_test_results_change, na.rm = TRUE))
p = data %>%
ggplot(aes_string("date", y)) +
geom_line(color = "#007EA7") +
geom_bar(stat = "identity", fill = "#007EA7", alpha = .5) +
scale_color_manual(values = wesanderson::wes_palette("Darjeeling1", 56, "continuous")) +
theme_minimal()
} else {
p = data %>%
ggplot(aes_string("date", y, color = "state")) +
geom_line() +
scale_color_manual(values = wesanderson::wes_palette("Darjeeling1", 56, "continuous")) +
theme_minimal()
}
if (grepl("change", y)) {
str = gsub("_change", "", y)
p = p + labs(x = "\ndate", y = sprintf("change in number of %s\n", str))
} else {
p = p + labs(x = "\ndate", y = sprintf("number of %s\n", gsub("_", " ", y)))
}
plotly::ggplotly(p)
}
plot_covid_log = function(data, y, state = TRUE) {
if (isFALSE(state)) {
data = data %>%
group_by(date) %>%
summarize(deaths = sum(deaths, na.rm = TRUE),
deaths_change = sum(deaths_change, na.rm = TRUE),
hospitalizations = sum(hospitalizations, na.rm = TRUE),
positive_test_results = sum(positive_test_results, na.rm = TRUE),
positive_test_results_change = sum(positive_test_results_change, na.rm = TRUE),
negative_test_results = sum(negative_test_results, na.rm = TRUE),
negative_test_results_change = sum(negative_test_results_change, na.rm = TRUE))
p = data %>%
mutate(y = log2(!!rlang::parse_quosure(y))) %>%
ggplot(aes(date, y)) +
geom_line(color = "#007EA7") +
labs(x = "\ndate", y = sprintf("log2 number of %s\n", gsub("_", " ", y))) +
scale_color_manual(values = wesanderson::wes_palette("Darjeeling1", 56, "continuous")) +
theme_minimal()
} else {
p = data %>%
mutate(y = log2(!!rlang::parse_quosure(y))) %>%
ggplot(aes(date, y, color = state)) +
geom_line() +
labs(x = "\ndate", y = sprintf("log2 number of %s\n", gsub("_", " ", y))) +
scale_color_manual(values = wesanderson::wes_palette("Darjeeling1", 56, "continuous")) +
theme_minimal()
}
plotly::ggplotly(p)
}